/*
 * DbPanel.java
 *
 * Created on December 16, 2008, 1:39 PM
 */

package gblend.db;

import javax.swing.JTree;
import org.jdesktop.application.Action;

/**
 *
 * @author  cjjin
 */
public class DbPanel extends javax.swing.JPanel {
  
    /** Creates new form DbPanel */
    public DbPanel()  {
        initComponents();
        
    }
    public JTree getTree()
    {
        return schemaTree;
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        dbComboBox = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        schemaTree = new javax.swing.JTree();
        jPanel3 = new javax.swing.JPanel();
        expandButton = new javax.swing.JButton();
        collapseButton = new javax.swing.JButton();

        setName("Form"); // NOI18N
        setLayout(new java.awt.BorderLayout());

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setLayout(new java.awt.BorderLayout());

        dbComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        dbComboBox.setFocusable(false);
        dbComboBox.setName("DblistComboBox"); // NOI18N
        jPanel1.add(dbComboBox, java.awt.BorderLayout.CENTER);

        add(jPanel1, java.awt.BorderLayout.PAGE_START);

        jPanel2.setName("jPanel2"); // NOI18N
        jPanel2.setLayout(new java.awt.BorderLayout());

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(gblend.GBlendApp.class).getContext().getResourceMap(DbPanel.class);
        schemaTree.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("schemaTree.border.title"))); // NOI18N
        schemaTree.setFont(resourceMap.getFont("schemaTree.font")); // NOI18N
        schemaTree.setDragEnabled(true);
        schemaTree.setModel(null);
        schemaTree.setName("schemaTree"); // NOI18N
        schemaTree.setShowsRootHandles(true);
        jScrollPane1.setViewportView(schemaTree);
        schemaTree.getAccessibleContext().setAccessibleName(resourceMap.getString("schemaTree.AccessibleContext.accessibleName")); // NOI18N

        jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(gblend.GBlendApp.class).getContext().getActionMap(DbPanel.class, this);
        expandButton.setAction(actionMap.get("expandSchemaTree")); // NOI18N
        expandButton.setName("expandButton"); // NOI18N
        expandButton.setPreferredSize(new java.awt.Dimension(25, 25));
        jPanel3.add(expandButton);

        collapseButton.setAction(actionMap.get("collapseSchemaTree")); // NOI18N
        collapseButton.setName("collapseButton"); // NOI18N
        collapseButton.setPreferredSize(new java.awt.Dimension(25, 25));
        jPanel3.add(collapseButton);

        jPanel2.add(jPanel3, java.awt.BorderLayout.PAGE_END);

        add(jPanel2, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void expandSchemaTree() {
        for (int i = 0; i < this.schemaTree.getRowCount(); i++) {
            this.schemaTree.expandRow(i);
        }
    }

    @Action
    public void collapseSchemaTree() {
        for (int i = 0; i < this.schemaTree.getRowCount(); i++) {
            this.schemaTree.collapseRow(i);
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton collapseButton;
    private javax.swing.JComboBox dbComboBox;
    private javax.swing.JButton expandButton;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTree schemaTree;
    // End of variables declaration//GEN-END:variables
 public javax.swing.JComboBox getDatabaseListComboBox() {
        return dbComboBox;
    }
}
